home *** CD-ROM | disk | FTP | other *** search
/ Mac Easy 2010 May / Mac Life Ubuntu.iso / casper / filesystem.squashfs / var / lib / python-support / python2.6 / orca / outloud.pyc (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2009-04-20  |  8.5 KB  |  259 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.6)
  3.  
  4. '''Outloud voice definitions using ACSS.
  5.  
  6. This module encapsulates Outloud-specific voice definitions.  It
  7. maps device-independent ACSS voice definitions into appropriate
  8. Outloud voice parameter settings.
  9.  
  10. '''
  11. __id__ = '$Id: outloud.py 4281 2008-10-08 22:05:56Z wwalker $'
  12. __author__ = 'T. V. Raman'
  13. __version__ = '$Revision: 4281 $'
  14. __date__ = '$Date: 2008-10-08 18:05:56 -0400 (Wed, 08 Oct 2008) $'
  15. __copyright__ = 'Copyright (c) 2005-2008 Google Inc.'
  16. __license__ = 'LGPL'
  17. import chnames
  18.  
  19. def makeSpecialCharMap():
  20.     '''Returns list of pairs mapping characters which are special for
  21.     Outloud speech server to their replacements.
  22.     '''
  23.     chars = '{\\}`'
  24.     return [ (ch, ' ' + chnames.getCharacterName(ch) + ' ') for ch in chars ]
  25.  
  26. _defined_voices = { }
  27.  
  28. def _update_map(table, key, format, settings):
  29.     '''Internal function to update acss->synth mapping.'''
  30.     table[key] = { }
  31.     for setting in settings:
  32.         _table[key][setting[0]] = format % setting[1:]
  33.     
  34.  
  35. _table = { }
  36. _table['family'] = {
  37.     'paul': ' `v1 ',
  38.     'male': ' `v1 ',
  39.     'harry': ' `v1 `vh65 `vb50 ',
  40.     'man': ' `v1 `vh65 `vb50 ',
  41.     'dennis': ' `v1  `vb0 ',
  42.     'frank': ' `v1 `vr100 ',
  43.     'betty': ' `v7 ',
  44.     'female': ' `v7 ',
  45.     'ursula': ' `v2 ',
  46.     'rita': ' `v2 `vr100 ',
  47.     'wendy': ' `v2 `vy50 ',
  48.     'kit': ' `v3 ',
  49.     'child': ' `v3 ' }
  50. _male_ap = [
  51.     (0, 0, 90),
  52.     (1, 13, 81),
  53.     (2, 26, 72),
  54.     (3, 39, 63),
  55.     (4, 52, 54),
  56.     (5, 65, 50),
  57.     (6, 74, 40),
  58.     (7, 83, 30),
  59.     (8, 87, 26),
  60.     (9, 92, 21)]
  61. _update_map(_table, ('male', 'average-pitch'), ' `vb%s `vh%s ', _male_ap)
  62. _update_map(_table, ('paul', 'average-pitch'), ' `vb%s `vh%s ', _male_ap)
  63. _update_map(_table, ('frank', 'average-pitch'), ' `vb%s `vh%s ', _male_ap)
  64. _man_ap = [
  65.     (0, 0, 90),
  66.     (1, 10, 85),
  67.     (2, 20, 80),
  68.     (3, 30, 70),
  69.     (4, 40, 60),
  70.     (5, 50, 60),
  71.     (6, 60, 50),
  72.     (7, 70, 40),
  73.     (8, 80, 30),
  74.     (9, 90, 20)]
  75. _update_map(_table, ('man', 'average-pitch'), ' `vb%s `vh% s', _man_ap)
  76. _update_map(_table, ('harry', 'average-pitch'), ' `vb%s `vh% s', _man_ap)
  77. _update_map(_table, ('dennis', 'average-pitch'), ' `vb%s `vh%s ', _male_ap)
  78. _female_ap = [
  79.     (0, 5, 70),
  80.     (1, 17, 66),
  81.     (2, 33, 62),
  82.     (3, 49, 58),
  83.     (4, 65, 54),
  84.     (5, 81, 50),
  85.     (6, 85, 55),
  86.     (7, 89, 60),
  87.     (8, 93, 65),
  88.     (9, 97, 69)]
  89. _update_map(_table, ('female', 'average-pitch'), ' `vb%s `vh% s', _female_ap)
  90. _update_map(_table, ('betty', 'average-pitch'), ' `vb%s `vh% s', _female_ap)
  91. _update_map(_table, ('ursula', 'average-pitch'), ' `vb%s `vh% s', _female_ap)
  92. _update_map(_table, ('rita', 'average-pitch'), ' `vb%s `vh% s', _female_ap)
  93. _update_map(_table, ('wendy', 'average-pitch'), ' `vb%s `vh% s', _female_ap)
  94. _child_ap = [
  95.     (0, 60, 33),
  96.     (1, 65, 29),
  97.     (2, 70, 26),
  98.     (3, 75, 23),
  99.     (4, 80, 20),
  100.     (5, 85, 17),
  101.     (6, 90, 14),
  102.     (7, 95, 11),
  103.     (8, 97, 8),
  104.     (9, 99, 5)]
  105. _update_map(_table, ('kit', 'average-pitch'), ' `vb%s `vh% s', _child_ap)
  106. _update_map(_table, ('child', 'average-pitch'), ' `vb%s `vh% s', _child_ap)
  107. _male_pr = [
  108.     (0, 0),
  109.     (1, 5),
  110.     (2, 15),
  111.     (3, 20),
  112.     (4, 25),
  113.     (5, 30),
  114.     (6, 47),
  115.     (7, 64),
  116.     (8, 81),
  117.     (9, 100)]
  118. _update_map(_table, ('male', 'pitch-range'), ' `vf%s  ', _male_pr)
  119. _update_map(_table, ('paul', 'pitch-range'), ' `vf%s  ', _male_pr)
  120. _update_map(_table, ('frank', 'pitch-range'), ' `vf%s  ', _male_pr)
  121. _update_map(_table, ('dennis', 'pitch-range'), ' `vf%s  ', _male_pr)
  122. _man_pr = [
  123.     (0, 0),
  124.     (1, 5),
  125.     (2, 15),
  126.     (3, 20),
  127.     (4, 25),
  128.     (5, 30),
  129.     (6, 47),
  130.     (7, 64),
  131.     (8, 81),
  132.     (9, 100)]
  133. _update_map(_table, ('man', 'pitch-range'), ' `vf%s  ', _man_pr)
  134. _update_map(_table, ('harry', 'pitch-range'), ' `vf%s  ', _man_pr)
  135. _female_pr = [
  136.     (0, 0),
  137.     (1, 5),
  138.     (2, 15),
  139.     (3, 20),
  140.     (4, 25),
  141.     (5, 30),
  142.     (6, 47),
  143.     (7, 64),
  144.     (8, 81),
  145.     (9, 100)]
  146. _update_map(_table, ('female', 'pitch-range'), ' `vf%s  ', _female_pr)
  147. _update_map(_table, ('betty', 'pitch-range'), ' `vf%s  ', _female_pr)
  148. _update_map(_table, ('ursula', 'pitch-range'), ' `vf%s  ', _female_pr)
  149. _update_map(_table, ('rita', 'pitch-range'), ' `vf%s  ', _female_pr)
  150. _update_map(_table, ('wendy', 'pitch-range'), ' `vf%s  ', _female_pr)
  151. _child_pr = [
  152.     (0, 0),
  153.     (1, 5),
  154.     (2, 15),
  155.     (3, 20),
  156.     (4, 25),
  157.     (5, 30),
  158.     (6, 47),
  159.     (7, 64),
  160.     (8, 81),
  161.     (9, 100)]
  162. _update_map(_table, ('kit', 'pitch-range'), ' `vf%s  ', _child_pr)
  163. _update_map(_table, ('child', 'pitch-range'), ' `vf%s  ', _child_pr)
  164. _male_stress = [
  165.     (0, 0),
  166.     (1, 5),
  167.     (2, 10),
  168.     (3, 15),
  169.     (4, 20),
  170.     (5, 25),
  171.     (6, 30),
  172.     (7, 35),
  173.     (8, 40),
  174.     (9, 45)]
  175. _update_map(_table, ('male', 'stress'), ' `vr%s  ', _male_stress)
  176. _update_map(_table, ('paul', 'stress'), ' `vr%s  ', _male_stress)
  177. _update_map(_table, ('frank', 'stress'), ' `vr%s  ', _male_stress)
  178. _update_map(_table, ('dennis', 'stress'), ' `vr%s  ', _male_stress)
  179. _update_map(_table, ('man', 'stress'), ' `vr%s  ', _male_stress)
  180. _update_map(_table, ('harry', 'stress'), ' `vr%s  ', _male_stress)
  181. _update_map(_table, ('female', 'stress'), ' `vr%s  ', _male_stress)
  182. _update_map(_table, ('betty', 'stress'), ' `vr%s  ', _male_stress)
  183. _update_map(_table, ('ursula', 'stress'), ' `vr%s  ', _male_stress)
  184. _update_map(_table, ('rita', 'stress'), ' `vr%s  ', _male_stress)
  185. _update_map(_table, ('wendy', 'stress'), ' `vr%s  ', _male_stress)
  186. _update_map(_table, ('kit', 'stress'), ' `vr%s  ', _male_stress)
  187. _update_map(_table, ('child', 'stress'), ' `vr%s  ', _male_stress)
  188. _male_richness = [
  189.     (0, 0, 60),
  190.     (1, 4, 78),
  191.     (2, 8, 80),
  192.     (3, 12, 84),
  193.     (4, 16, 88),
  194.     (5, 20, 92),
  195.     (6, 24, 93),
  196.     (7, 28, 95),
  197.     (8, 32, 97),
  198.     (9, 36, 100)]
  199. _update_map(_table, ('male', 'richness'), ' `vy%s  `vv%s ', _male_richness)
  200. _update_map(_table, ('paul', 'richness'), ' `vy%s  `vv%s ', _male_richness)
  201. _update_map(_table, ('frank', 'richness'), ' `vy%s  `vv%s ', _male_richness)
  202. _update_map(_table, ('dennis', 'richness'), ' `vy%s  `vv%s ', _male_richness)
  203. _update_map(_table, ('man', 'richness'), ' `vy%s  `vv%s ', _male_richness)
  204. _update_map(_table, ('harry', 'richness'), ' `vy%s  `vv%s ', _male_richness)
  205. _update_map(_table, ('female', 'richness'), ' `vy%s  `vv%s ', _male_richness)
  206. _update_map(_table, ('betty', 'richness'), ' `vy%s  `vv%s ', _male_richness)
  207. _update_map(_table, ('ursula', 'richness'), ' `vy%s  `vv%s ', _male_richness)
  208. _update_map(_table, ('rita', 'richness'), ' `vy%s  `vv%s ', _male_richness)
  209. _update_map(_table, ('wendy', 'richness'), ' `vy%s  `vv%s ', _male_richness)
  210. _update_map(_table, ('kit', 'richness'), ' `vy%s  `vv%s ', _male_richness)
  211. _update_map(_table, ('child', 'richness'), ' `vy%s  `vv%s ', _male_richness)
  212.  
  213. def getrate(r):
  214.     return r
  215.  
  216.  
  217. def getvoicelist():
  218.     return _table['family'].keys()
  219.  
  220.  
  221. def getvoice(acss):
  222.     '''Memoized function that returns  synthesizer code for
  223.     specified  ACSS setting.
  224.     Synthesizer code is a tupple of the form (open,close)
  225.     where open sets the voice, and close resets it.'''
  226.     name = acss.name()
  227.     if name in _defined_voices:
  228.         return _defined_voices[name]
  229.     _defined_voices[name] = acss2voice(acss)
  230.     return _defined_voices[name]
  231.  
  232.  
  233. def acss2voice(acss):
  234.     '''Return synthesizer code.'''
  235.     code = ''
  236.     familyName = 'male'
  237.     if 'family' in acss:
  238.         familyName = acss['family']['name']
  239.         code += _table['family'][familyName]
  240.     
  241.     if 'rate' in acss:
  242.         code += ' `vs%s' % int(acss['rate'])
  243.     
  244.     voice = ''
  245.     for d in [
  246.         'average-pitch',
  247.         'pitch-range',
  248.         'richness',
  249.         'stress']:
  250.         if d in acss:
  251.             voice += _table[(familyName, d)][int(acss[d])]
  252.             continue
  253.     
  254.     if code or voice:
  255.         code = '%s %s' % (code, voice)
  256.     
  257.     return (code, ' `v1 ')
  258.  
  259.